from flask import Flask,request,jsonify
import demo
import os
import cv2

app = Flask(__name__)
'***获取上级目录***'
basedir = os.path.abspath(os.path.join(os.getcwd(), "../"))
'***获取当前目录***'
# basedir = os.path.abspath(os.path.dirname(__name__))



# 上传图片，进行检测
@app.route('/detectionImage',methods=["POST","GET"])
def detectionImage():
    #上传图片并保存
    image = request.files['image']
    path = os.path.join(basedir , 'data','demo')
    file_path = os.path.join(path,image.filename)
    image.save(file_path)
    #调用模型识别数据
    sess,net=demo.setNetWork()
    im = cv2.imread(file_path)
    cls, dets =demo.demo(sess,net,im)
    return {"type": cls, "data": dets.tostring()}


if __name__ == "__main__":
	app.run(host='0.0.0.0', port=8099, debug=True)





